﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using QuailDashboard.View.Data;

namespace QuailDashboard.View.Controls
{
    public class HierarchalTreeViewItem : TreeViewItem
    {
        protected override DependencyObject GetContainerForItemOverride()
        {
            return new HierarchalTreeViewItem();
        }

        protected override bool IsItemItsOwnContainerOverride(object item)
        {
            return item is HierarchalTreeViewItem;
        }

        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            HierarchicalDataTemplate hierarchicalDataTemplate = ItemTemplate as HierarchicalDataTemplate;
            var testdata = item as IHierarchalData;
            if (hierarchicalDataTemplate != null && testdata != null)
            {
                hierarchicalDataTemplate.ItemsSource = new Binding("Items");
                testdata.Populate();
            }

            base.PrepareContainerForItemOverride(element, item);
        }
    }
}
